<!DOCTYPE html>
<html>
	<head>
		<title>Datatable: Autosuggest</title>
		<link rel="stylesheet" href="../../../codebase/webix.css" type="text/css" charset="utf-8">
		<script src="../../../codebase/webix.js" type="text/javascript" charset="utf-8"></script>

		<link rel="stylesheet" type="text/css" href="../common/samples.css">
		<script src="../common/testdata.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>

		<div class='header_comment'>Editor with autosuggest</div>

        <div class='sample_comment'>Using "suggest" property to implement suggesting.<br/>Try to edit column Released</div>
        <div id="testA"></div>
        <br/>
		<div class='sample_comment'>Using onAfterEditStart/onAfterEditStop to implement suggesting.<br/>Try to edit column Released</div>
		<div id="testB"></div>

		<script type="text/javascript" charset="utf-8">

		webix.ready(function(){
			var years = [];
			for (var i = 1970; i < 2015; i++)
				years.push({ id: i, value: i});

			var year_suggest_a = {
				view: "suggest",
				data:years,
				width: 70, yCount:8
			};

			var grida = new webix.ui({
				container:"testA",
				view:"datatable",
				columns:[
					{ id:"rank",	editor:"text",		header:"", css:"rank",  		width:50},
					{ id:"title",	editor:"text",		header:"Film title",width:200},
					{ id:"year",	editor:"text",		header:"Released" , width:80, suggest:year_suggest_a},
					{ id:"votes",	editor:"text",		header:"Votes", 	width:100}
				],
				editable:true,
				autoheight:true,
				autowidth:true,
				data: [
					{ id:1, title:"The Shawshank Redemption", year:1994, votes:678790, rating:9.2, rank:1},
					{ id:2, title:"The Godfather", year:1972, votes:511495, rating:9.2, rank:2}
				]
			});



            var year_suggest_b = webix.ui({
                view: "suggest",
                data:years,
                width: 70, yCount:8
            });

            var gridb = new webix.ui({
                container:"testB",
                view:"datatable",
                columns:[
                    { id:"rank",	editor:"text",		header:"", css:"rank",  		width:50},
                    { id:"title",	editor:"text",		header:"Film title",width:200},
                    { id:"year",	editor:"text",		header:"Released" , width:80},
                    { id:"votes",	editor:"text",		header:"Votes", 	width:100}
                ],
                editable:true,
                autoheight:true,
                autowidth:true,
                data: [
                    { id:1, title:"The Shawshank Redemption", year:1994, votes:678790, rating:9.2, rank:1},
                    { id:2, title:"The Godfather", year:1972, votes:511495, rating:9.2, rank:2}
                ]
            });
			
			gridb.attachEvent("onAfterEditStart", function(object) {
				if (object.column == "year") {
					var editor = this.getEditor(object);
					year_suggest_b.linkInput(editor.getInputNode());
				}
			});

			gridb.attachEvent("onAfterEditStop", function(object) {
				year_suggest_b.hide();
			});
		});
		</script>
	</body>
</html>